using UnityEngine;
using Voodoo.Sauce.Common.Utils.Data.ScreenUtilsConfig;

namespace Voodoo.Sauce.Internal.Utils
{
	public static class ScreenSizeUtils
	{
		private const int CUTOUT_HEIGHT_ANDROID = 80;

		private static Vector2 _nativeScreenResolution;

		private static VoodooScreenUtilsConfig _config;

		private static Vector2 GetUnityResolutions()
		{
			return new Vector2Int(Screen.width, Screen.height);
		}

		private static Vector2 GetNativeResolutions()
		{
			if (_nativeScreenResolution.x != 0f && _nativeScreenResolution.y != 0f)
			{
				return _nativeScreenResolution;
			}
			if (_config == null)
			{
				_config = VoodooScreenUtilsConfig.Load();
			}
			int num = Display.main.systemWidth;
			int num2 = Display.main.systemHeight;
			if (!_config.IsAndroidRenderOutsideSafeArea)
			{
				if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight)
				{
					num -= 80;
				}
				else
				{
					num2 -= 80;
				}
			}
			_nativeScreenResolution = new Vector2Int(num, num2);
			return _nativeScreenResolution;
		}

		public static Vector2 GetResolutionNativeToUnityRatio()
		{
			Vector2 unityResolutions = GetUnityResolutions();
			Vector2 nativeResolutions = GetNativeResolutions();
			if (nativeResolutions.x == 0f || nativeResolutions.y == 0f || unityResolutions.y == 0f || unityResolutions.x == 0f)
			{
				return new Vector2(1f, 1f);
			}
			return new Vector2(unityResolutions.x / nativeResolutions.x, unityResolutions.y / nativeResolutions.y);
		}

		public static Vector2 GetResolutionUnityToNativeRatio()
		{
			Vector2 unityResolutions = GetUnityResolutions();
			Vector2 nativeResolutions = GetNativeResolutions();
			if (nativeResolutions.x == 0f || nativeResolutions.y == 0f || unityResolutions.y == 0f || unityResolutions.x == 0f)
			{
				return new Vector2(1f, 1f);
			}
			return new Vector2(nativeResolutions.x / unityResolutions.x, nativeResolutions.y / unityResolutions.y);
		}

		public static float GetDpi()
		{
			return Screen.dpi;
		}
	}
}
